home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / LL_LAND.ZIP / LL_LAND.C < prev    next >
C/C++ Source or Header  |  1993-05-11  |  4KB  |  192 lines

  1. //
  2. // Lord Logics Landscape
  3. //
  4. // Use it, read it, learn from it, do whatever you want with it . . .
  5. // If it screws up ur system, its not my fault.  If it doesn't work for you,
  6. // its not my fault.
  7. //
  8. // To compile   : qcl -AH -c ll_land.c
  9. // To assemble  : ml -c ll_1.asm
  10. // To link      : link land ll_1;
  11. // To run       : ll_land
  12. //
  13.  
  14. #include <math.h>
  15. #include "ll_gfx.h"
  16. #include "ll_key.h"
  17.  
  18. extern void ll_xinit();
  19. extern void ll_page();
  20. extern char ll_sin(int);
  21. extern char ll_cos(int);
  22. extern void land_clr();
  23. extern void land_put(int, int, int, int);
  24. extern  int     far     *ll_table;
  25.  
  26. #define LL_PALSIZE 775
  27. char far NEW_PAL[LL_PALSIZE];
  28.  
  29. /*
  30.    void ll_delta();
  31.    This routine determines the radius and theta angles for the cubical
  32.    landscape region.  Call this routine passing the buffer (size: int
  33.    40*40*2) as well as the DX and DZ values.  These values are the change
  34.    in X and Z between each pixel plot in the landscape.
  35. */
  36. void    ll_delta(int far *table, int dx, int dz)
  37. {
  38. int     c,x,z,r,theta;
  39.  
  40.     c=0;
  41.     for (z=23; z>-23; z--)
  42.     for (x=-23; x<23; x++)
  43.     {
  44.         r=(int)sqrt((double)((long)((long)dz*(long)dz*(long)z*(long)z)+(long)((long)dx*(long)dx*(long)x*(long)x)));
  45.         if ((z==0) && (x<0))
  46.             theta=270;
  47.         else
  48.         if ((z==0) && (x>0))
  49.             theta=90;
  50.         else
  51.         if (z==0)
  52.             theta=0;
  53.         else
  54.         if (z<0)
  55.             theta=(int)((double)(atan( (double)((long)dx*(long)x)/(double)((long)dz*(long)z) )*180/3.1415926))+180;
  56.         else
  57.             theta=(int)((double)(atan( (double)((long)dx*(long)x)/(double)((long)dz*(long)z) )*180/3.1415926));
  58.  
  59.         if (theta<0) theta+=360;
  60.  
  61.         /*
  62.         printf("%d,%d: %d %d\n",x+23,z+23,r,theta);
  63.         if (kbhit()) { while (kbhit()) getch(); getch(); }
  64.         */
  65.  
  66.         table[c]=r;
  67.         table[c+1]=theta;
  68.  
  69.         c+=2;
  70.     }
  71. }
  72.  
  73. main()
  74. {
  75. int     x;
  76. int     y;
  77. int     z;
  78. long    c=0;
  79. long    d=0;
  80. long    w=0;
  81. int     water=0;
  82. int     wdelta=2;
  83. int     adelta=2;
  84. int     xydelta=0;
  85. int     alpha=0;
  86.  
  87.  
  88.     printf("-=[    Initializing Land Mesh    ]=-\n");
  89.     ll_delta(ll_table,35,35);
  90.  
  91.  
  92.     /* Routines not provided for this section.  These are a part of
  93.        my graphics routines which I am no releasing.  Code is given
  94.        to do the necessary stuff.  This code initializes a 13h video
  95.        mode and saves the text screen for restoration.
  96.  
  97.     if ((pal=ll_getsys())==0)
  98.     {
  99.         printf("VGA not found or insufficient memory.\n");
  100.         exit(1);
  101.     }
  102.     */
  103.  
  104.     // Substitute code
  105.     _asm
  106.     {
  107.         mov     ax,0013h
  108.         int     10h
  109.     }
  110.  
  111.     ll_palramp(NEW_PAL,1,64,0,63,0,0,32,0);
  112.     ll_palramp(NEW_PAL,64,32,0,32,0,63,63,63);
  113.     ll_palramp(NEW_PAL,96,159,63,63,63,63,63,63);
  114.     NEW_PAL[0]=0;
  115.     NEW_PAL[1]=0;
  116.     NEW_PAL[2]=0;
  117.     NEW_PAL[3]=3;
  118.     NEW_PAL[4]=0;
  119.     NEW_PAL[5]=46;
  120.  
  121.     ll_xinit();             // Initialize a 320x200 unchained mode
  122.  
  123.     ll_palput(NEW_PAL);
  124.  
  125.     x=0;
  126.     y=0;
  127.     adelta=0;
  128.     xydelta=0;
  129.  
  130.     ll_keyswap();
  131.  
  132.     while (!ll_keypressed(_ESC))
  133.     {
  134.         ll_page();
  135.         land_clr();
  136.         land_put(x,y,water,alpha);
  137.  
  138.         if (ll_keypress(_UP))
  139.             {if (xydelta<5) xydelta++;}
  140.         else
  141.             {if (xydelta>0) xydelta--;}
  142.  
  143.         if (ll_keypress(_DOWN))
  144.             {if (xydelta>-5) xydelta--;}
  145.         else
  146.             {if (xydelta<0) xydelta++;}
  147.  
  148.         if (ll_keypress(_RIGHT))
  149.             {if (adelta>-10) adelta--;}
  150.         else
  151.             {if (adelta<0) adelta++;}
  152.  
  153.         if (ll_keypress(_LEFT))
  154.             {if (adelta<10) adelta++;}
  155.         else
  156.             {if (adelta>0) adelta--;}
  157.  
  158.         if (ll_keypress(_MIDDLE))
  159.             adelta=0;
  160.         if (ll_keypress(_SPACE))
  161.             water+=wdelta;
  162.  
  163.         if (water<0) {wdelta=2; water=0;}
  164.         if (water>160) wdelta=-2;
  165.  
  166.         alpha+=adelta;
  167.         while (alpha<0) alpha+=360;
  168.         while (alpha>=360) alpha-=360;
  169.  
  170.         x-=ll_sin(alpha)*xydelta/128;
  171.         y-=ll_cos(alpha)*xydelta/128;
  172.  
  173.         if (x>206) x=206;
  174.         if (y>206) y=206;
  175.         if (y<0) y=0;
  176.         if (x<0) x=0;
  177.     }
  178.  
  179.     ll_keyswap();
  180.  
  181.     /* Another routine not given.
  182.     ll_putsys();
  183.     */
  184.  
  185.     // Substitute code
  186.     _asm
  187.     {
  188.         mov     ax,0003h
  189.         int     10h
  190.     }
  191. }
  192.